package com.dataseek.iot.mysql.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dataseek.iot.mysql.entity.Device;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author cc
 * @Title: 自定义设备接口
 * @Description: 自定义设备接口
 * @date 2021/10/191:18 下午
 * @since 1.0
 */
public interface MyDeviceMapper extends BaseMapper<Device> {

    /**
     * 根据设备ID查询用户信息
     * @param deviceId
     * @return
     */
    @Select("SELECT * from `user` u where role_id  = (select role_inner_id as id from role WHERE line_id = " +
            " (SELECT line_id  from device where device_inner_id = #{deviceId})) ")
    List<Map<String, Object>> findUsersByDeviceId(@Param("deviceId") String deviceId);

    @Select("SELECT * from `user` u where role_id  = (select role_inner_id as id from role WHERE line_id = " +
            " (SELECT line_id  from device where device_code = #{deviceCode})) ")
    List<Map<String, Object>> findUsersByDeviceCode(@Param("deviceCode") String deviceCode);

}
